package com.k1998.mybatis.controller;

import com.k1998.mybatis.service.StudentService;
import com.k1998.mybatis.utils.HashMapUtils;
import com.k1998.mybatis.utils.QueryInfo;
import com.k1998.mybatis.bean.Student;
import com.k1998.mybatis.dao.IStudentDao;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = {"学生个人信息Api文档"})
public class StudentController {
    @Autowired
    private StudentService studentService;
    @Autowired
    private IStudentDao iStudentDao;

    @PostMapping("/allStudent")
    @ApiOperation(value = "查询学生个人信息", notes="查询学生个人信息", httpMethod = "POST")
    public String getAll(@RequestBody QueryInfo queryInfo) {
        return studentService.getAllStudents(queryInfo);
    }

    @PostMapping("/detailStudent")
    @ApiOperation(value = "详细查询", notes="详细查询", httpMethod = "POST")
    public String detailStudent(@RequestBody Student student){
        return HashMapUtils.toHashMap(iStudentDao.detailStudent(student));
    }

    @PostMapping("/insertStudent")
    @ApiOperation(value = "添加学生个人信息", notes="添加学生个人信息", httpMethod = "POST")
    public String insertStudent(@RequestBody Student student){
        return iStudentDao.insertStudent(student) >0?"success":"error";
    }

    @PostMapping("/updateStudent")
    @ApiOperation(value = "修改学生个人信息", notes="修改学生个人信息", httpMethod = "POST")
    public String updateStudent(@RequestBody Student student){
        return iStudentDao.updateStudent(student) >0?"success":"error";
    }

    @PostMapping("/deleteStudent")
    @ApiOperation(value = "删除学生个人信息", notes="删除学生个人信息", httpMethod = "POST")
    public String deleteStudent(@RequestBody Student student){
        return iStudentDao.deleteStudent(student) >0?"success":"error";
    }

}
